package com.maimao.model.dynamicform.props;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.maimao.model.goods.enums.FormType;
import com.maimao.model.goods.vo.SpecDetailVo;

import java.io.Serializable;

/**
 * 下拉框
 *
 * @author MaoLin Wang
 * @date 2020/12/19 9:20 下午
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SelectProps extends Props implements Serializable {

    private static final long serialVersionUID = -9172593218249185343L;
    /**
     * 可选值：'default' | 'multiple' | 'tags' | 'combobox' 仅在多选时需要设置为multiple
     */
    private String mode;

    /**
     * 单选时有效
     */
    private boolean clearable;

    private boolean filterable;


    private String placeholder;


    public SelectProps() {
        placeholder = "请选择%s";
        filterable = true;
    }

    public static SelectProps getDefaultSelectProps(SpecDetailVo spec, String formType) {
        SelectProps selectProps = new SelectProps();
        if (FormType.SELECT.getName().equals(formType)) {
            selectProps.setClearable(true);
        } else {
            selectProps.setMode("multiple");
        }
        selectProps.setPlaceholder(String.format(selectProps.getPlaceholder(), spec.getName()));
        return selectProps;
    }

    public String getMode() {
        return mode;
    }

    public void setMode(String mode) {
        this.mode = mode;
    }

    public boolean isClearable() {
        return clearable;
    }

    public void setClearable(boolean clearable) {
        this.clearable = clearable;
    }

    public boolean isFilterable() {
        return filterable;
    }

    public void setFilterable(boolean filterable) {
        this.filterable = filterable;
    }

    public String getPlaceholder() {
        return placeholder;
    }

    public void setPlaceholder(String placeholder) {
        this.placeholder = placeholder;
    }
}
